package top.yamhk.agent.entity.response;

import lombok.Data;
import top.yamhk.agent.entity.enums.ErrorCodes;

import java.io.Serializable;

/**
 * 矩阵响应类
 *
 * @author 庆 HongKong
 * @date 2019/4/14 19:03
 */
@Data
public class MatrixResponse<T> implements Serializable {
    /**
     * 响应码
     */
    private String code;
    /**
     * 响应消息
     */
    private String msg;
    /**
     * 数据
     */
    private T data;

    public MatrixResponse() {
        this.code = ErrorCodes.SUCCESS.getCode();
        this.msg = ErrorCodes.SUCCESS.getMessage();
    }

    public static MatrixResponse ok() {
        MatrixResponse matrixResponse = new MatrixResponse();
        matrixResponse.setCode(ErrorCodes.SUCCESS.getCode());
        matrixResponse.setMsg(ErrorCodes.SUCCESS.getMessage());
        return matrixResponse;
    }

    public static MatrixResponse ng() {
        MatrixResponse matrixResponse = new MatrixResponse();
        matrixResponse.setCode(ErrorCodes.ERROR_SIMPLE.getCode());
        matrixResponse.setMsg(ErrorCodes.ERROR_SIMPLE.getMessage());
        return matrixResponse;
    }

    public static MatrixResponse code(ErrorCodes codes) {
        MatrixResponse matrixResponse = new MatrixResponse();
        matrixResponse.setCode(codes.getCode());
        matrixResponse.setMsg(codes.getMessage());
        return matrixResponse;
    }

    public MatrixResponse withMessage(String message) {
        this.msg = message;
        return this;
    }

    public MatrixResponse withData(T anyThing) {
        this.data = anyThing;
        return this;
    }
}